import tkinter as tk


def login():
    username = entry_username.get()
    password = entry_password.get()

    if username == "admin" and password == "password":
        open_new_page()
    else:
        label_result.config(text="Login failed", fg="red")


def open_new_page():
    # 创建新页面的顶级窗口
    new_window = tk.Toplevel(window)
    new_window.title("新页面")

    # 在新页面中显示示例内容
    label_example = tk.Label(new_window, text="这是一个新页面示例")
    label_example.pack()

    # 销毁登录页面
    window.destroy()


# 创建主窗口
window = tk.Tk()
window.title("登录界面")

# 创建用户名和密码的标签和输入框
label_username = tk.Label(window, text="用户名:")
label_username.pack()
entry_username = tk.Entry(window)
entry_username.pack()

label_password = tk.Label(window, text="密码:")
label_password.pack()
entry_password = tk.Entry(window, show="*")
entry_password.pack()

# 创建登录按钮
button_login = tk.Button(window, text="登录", command=login)
button_login.pack()

# 创建用于显示登录结果的标签
label_result = tk.Label(window)
label_result.pack()

# 运行主循环
window.mainloop()
